package com.gzw.dms.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.ShippingOrderInfo;
import com.gzw.dms.bean.WaybillAdjustmentInfo;

import java.util.List;

/**
 * Created by Administrator on 2017/4/21.
 */
public class OrderChangeAdapter extends RecyclerView.Adapter {
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
        boolean onItemLongClick(int position);
    }
    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }
    private static final String TAG = AbonrmalAdapter.class.getSimpleName();
    private List<WaybillAdjustmentInfo> list;
    public OrderChangeAdapter(List<WaybillAdjustmentInfo> list) {
        this.list = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_orderchange, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        WaybillAdjustmentInfo waybillAdjustmentInfo = list.get(i);
        ShippingOrderInfo shippingOrderInfo = waybillAdjustmentInfo.getShippingOrder();
        holder.tv_shiping_order_num.setText("货运编号:"+shippingOrderInfo.getShiping_order_num());
        holder.tv_order_goid.setText("出货订单号:"+shippingOrderInfo.getShiping_order_goid());

        holder.tv_send_time.setText("申请人姓名:"+waybillAdjustmentInfo.getApplicant_name());
        holder.tv_end_address.setText("终到位置:"+shippingOrderInfo.getEnd_address());
        holder.tv_custom_name.setText("受理机构:"+shippingOrderInfo.getSend_mechanism());
        holder.tv_edit.setText("申请原因:"+waybillAdjustmentInfo.getApplicant_message());
        if(waybillAdjustmentInfo.getApplicant_type()==0) {
            holder.tv_sx.setText("申请类型:"+ "运单调整");
        }else if (waybillAdjustmentInfo.getApplicant_type()==1) {
            holder.tv_sx.setText("申请类型:"+ "取消签收");
        }
        holder.tv_sign_time.setText("申请时间:" + waybillAdjustmentInfo.getApplicant_time());


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView tv_order_goid;
        public TextView tv_shiping_order_num;
        public TextView tv_send_time;
        public TextView tv_end_address;
        public TextView tv_custom_name;
        public TextView tv_sx;
        public TextView tv_sign_time;
        public TextView tv_edit;

        public int position;
        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_order_goid = (TextView) itemView.findViewById(R.id.ic_shiping_order_goid).findViewById(R.id.tv_name);
            tv_shiping_order_num = (TextView) itemView.findViewById(R.id.ic_shiping_order_num).findViewById(R.id.tv_name);
            tv_send_time = (TextView) itemView.findViewById(R.id.ic_send_time).findViewById(R.id.tv_name);
            tv_end_address = (TextView) itemView.findViewById(R.id.ic_end_address).findViewById(R.id.tv_name);
            tv_custom_name = (TextView) itemView.findViewById(R.id.ic_custom_name).findViewById(R.id.tv_name);
            tv_sx = (TextView) itemView.findViewById(R.id.ic_sx).findViewById(R.id.tv_name);
            tv_sign_time = (TextView) itemView.findViewById(R.id.ic_sign_time).findViewById(R.id.tv_name);
            tv_edit = (TextView) itemView.findViewById(R.id.ic_reason).findViewById(R.id.tv_name);;
            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
